<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of settings
 *
 * @author QUYET
 */
class Admin extends Admin_Controller {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model('settings_m');
    }

    function index() {
        $this->settings();
    }

    function settings() {
        $settings = $this->settings_m->get_settings();
        if (isset($_POST['submit'])) {
            $setting_data = array();
            foreach ($settings as $setting) {
                if ($setting['type'] == 'text') {
                    $this->db->update('settings', array('value' => $_POST[$setting['name']]), array('name' => $setting['name']));
                }
                if ($setting['type'] == 'checkbox') {
                    if(isset ($_POST[$setting['name']])){
                        $this->db->update('settings', array('value' => 1), array('name' => $setting['name']));
                    } else{
                        $this->db->update('settings', array('value' => 0), array('name' => $setting['name']));
                    }
                }
            }
            redirect(current_url());
        } else {
            $this->_data['settings'] = $settings;
            $this->display_admin('settings');
        }
    }

    function ajax_save_setting() {
        
    }

}

?>
